package com.fx.service;

import com.fx.dao.UserDao;
import com.fx.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * des:
 *
 * @author fxiao
 * @date 2020/12/10 17:39
 */
@Service
public class UserService implements UserDetailsService {
    @Autowired
    private UserDao dao;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = dao.findUserByUsername(username);
        if(user==null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return user;
    }

    @Transactional
    public void deleteByUsername(String userName){
        dao.deleteByUsername(userName);
    }
}
